<#include "/macro.include"/>
<#include "/java_copyright.include">
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
package ${basepackage}.app.model;

import java.sql.Timestamp;

import javax.persistence.*;

import org.hibernate.annotations.Cascade;
import org.hibernate.validator.constraints.*;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.validation.constraints.*;

import ${basepackage}.framework.base.dao.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;

<#include "/author.include">
@Entity
@Table(name = "${table.sqlName}")
public class ${className} extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;

	
	<@generateFields/>
	<@generateCompositeIdConstructorIfis/>
	<@generatePkProperties/>
	<@generateNotPkProperties/>
	<@generateJavaOneToMany/>
	<@generateJavaManyToOne/>

}

<#macro generateFields>


	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	<#list table.columns as column>
	<#if !column.pk>
	<#if !column.isForeignKey>
	<#if column.isEditable>
	${column.hibernateValidatorExprssion}
	</#if>
	@Column(name = "${column.sqlName}", unique = ${column.unique?string}, nullable = ${column.nullable?string}, insertable = true, updatable = true, length = ${column.size})
	private ${column.javaType} ${column.columnNameLower}; //${column.displayName}
	
	</#if>
	</#if>	
	</#list>
	
	
	//columns END


</#macro>

<#macro generateCompositeIdConstructorIfis>

	
</#macro>

<#macro generatePkProperties>
	
	
</#macro>

<#macro generateNotPkProperties>
<#list table.columns as column>
<#if !column.pk>
<#if !column.isForeignKey>
	public ${column.javaType} get${column.columnName}() {
		return this.${column.columnNameLower};
	}
	
	public void set${column.columnName}(${column.javaType} value) {
		this.${column.columnNameLower} = value;
	}

</#if>
</#if>
</#list>

</#macro>

<#macro generateJavaOneToMany>

</#macro>

<#macro generateJavaManyToOne>
<#list table.importedKeys.associatedTables?values as foreignKey>
<#assign fkSqlTable = foreignKey.sqlTable>
<#assign fkTable    = fkSqlTable.className>
<#assign fkPojoClass = fkSqlTable.className>
<#assign fkPojoClassVar = fkPojoClass?uncap_first>

	@ManyToOne(fetch = FetchType.LAZY)
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	@JoinColumns({
	<#list foreignKey.parentColumns?values as fkColumn>
		@JoinColumn(name = "${fkColumn}") <#if fkColumn_has_next>,</#if>
	</#list>
	})
	private ${fkPojoClass} ${fkPojoClassVar};
	public void set${fkPojoClass}(${fkPojoClass} ${fkPojoClassVar}){
		this.${fkPojoClassVar} = ${fkPojoClassVar};
	}

	@JsonIgnore
	public ${fkPojoClass} get${fkPojoClass}() {
		return ${fkPojoClassVar};
	}
</#list>
</#macro>

